import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class ColorChangerDialog extends JDialog{
	JSpinner spinnerRed;
	JSpinner spinnerGreen;
	JSpinner spinnerBlue;
	JSpinner spinnerAlpha;
	boolean doChange;
	public ColorChangerDialog(float[] tabColor) {
		setTitle("Color Changer");
		getContentPane().setLayout(null);
		
		setSize(281, 222);
		
		JLabel lblSelectTheColor = new JLabel("Select the color you want:");
		lblSelectTheColor.setBounds(10, 11, 230, 22);
		lblSelectTheColor.setFont(new Font("Arial", Font.BOLD, 18));
		getContentPane().add(lblSelectTheColor);
		
		JLabel lblRed = new JLabel("RED (0-255):");
		lblRed.setFont(new Font("Arial", Font.BOLD, 13));
		lblRed.setBounds(33, 44, 90, 14);
		getContentPane().add(lblRed);
		
		JLabel lblGreen = new JLabel("GREEN (0-255):");
		lblGreen.setFont(new Font("Arial", Font.BOLD, 13));
		lblGreen.setBounds(33, 69, 102, 14);
		getContentPane().add(lblGreen);
		
		JLabel lblBlue = new JLabel("BLUE (0-255):");
		lblBlue.setFont(new Font("Arial", Font.BOLD, 13));
		lblBlue.setBounds(34, 94, 89, 14);
		getContentPane().add(lblBlue);
		
		JLabel lblAlpha = new JLabel("ALPHA (0-255):");
		lblAlpha.setFont(new Font("Arial", Font.BOLD, 13));
		lblAlpha.setBounds(33, 119, 107, 14);
		getContentPane().add(lblAlpha);
		
		JButton btnOk = new JButton("Ok");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				doChange=true;
				dispose();
			}
		});
		btnOk.setBounds(10, 149, 119, 23);
		getContentPane().add(btnOk);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				doChange=false;
				dispose();
			}
		});
		btnCancel.setBounds(139, 149, 116, 23);
		getContentPane().add(btnCancel);
		
		SpinnerNumberModel modelSpinner1 = new SpinnerNumberModel(tabColor[0]*255, 0.0, 255.0, 1.0);  
		SpinnerNumberModel modelSpinner2 = new SpinnerNumberModel(tabColor[1]*255, 0.0, 255.0, 1.0);  
		SpinnerNumberModel modelSpinner3 = new SpinnerNumberModel(tabColor[2]*255, 0.0, 255.0, 1.0);  
		SpinnerNumberModel modelSpinner4 = new SpinnerNumberModel(tabColor[3]*255, 0.0, 255.0, 1.0);  
		
		spinnerRed = new JSpinner(modelSpinner1);
		spinnerRed.setBounds(159, 44, 66, 20);
		getContentPane().add(spinnerRed);
		
		spinnerGreen = new JSpinner(modelSpinner2);
		spinnerGreen.setBounds(159, 67, 66, 20);
		getContentPane().add(spinnerGreen);
		
		spinnerBlue = new JSpinner(modelSpinner3);
		spinnerBlue.setBounds(159, 92, 66, 20);
		getContentPane().add(spinnerBlue);
		
		spinnerAlpha = new JSpinner(modelSpinner4);
		spinnerAlpha.setBounds(159, 117, 66, 20);
		getContentPane().add(spinnerAlpha);
		
		doChange=false;
	}
	
	public double getRed(){
		return (double) spinnerRed.getValue()/255;
		
	}
	
	public double getGreen(){
		return (double) spinnerGreen.getValue()/255;
		
	}
	
	public double getBlue(){
		return (double) spinnerBlue.getValue()/255;
		
	}
	
	public double getAlpha(){
		return (double) spinnerAlpha.getValue()/255;
		
	}
	
	public void setDoChange(boolean doChange){
		this.doChange=doChange;
	}
	
	public boolean getDoChange(){
		return doChange;
	}
}
